package com.jinsi.controller.yrf;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.constant.YrfConstant;
import com.jinsi.pojo.Department;
import com.jinsi.service.yrf.DepartmentService;
import com.jinsi.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: 86185
 * @description: 部门管理
 * @date 2022/9/13
 */
@RestController

@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 分页获取数据（模糊查询）
     * @param page 分页
     * @param limit 分页
     * @param deptName 模糊查
     * @param admintorName 模糊查
     * @param deptCreatdate 模糊查
     * @param deptState 模糊查
     * @param deptParentId 模糊查
     * @return 前端需要类型
     */
    @RequestMapping("/getAll")
    public R getAll(Integer page, Integer limit, String deptName, String admintorName, Date deptCreatdate, String deptState, Integer deptParentId){
        PageHelper.startPage(page,limit);
        List<Department> all = departmentService.getAll(deptName,admintorName,deptCreatdate,deptState,deptParentId);
        PageInfo<Department> pageInfo = new PageInfo<>(all);

        return R.custom(YrfConstant.LAYUI_CODE,
                YrfConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());

    }

    /**
     * 修改是否启用表单按钮
     * @param deptId 根据deptId修改
     * @param deptState 要修改的状态码
     * @return 状态
     */
    @RequestMapping("/updState")
    public R updatedeptState(int deptId,String deptState){
        departmentService.updatedeptState(deptId,deptState);
        return R.ok("成功");
    }

    /**
     *添加部门管理列表
     * @param department 添加的部门
     * @return 状态码
     */
    @RequestMapping("/add")
    public R departmentadd(@Valid Department department){
        departmentService.departmentadd(department);
        return R.ok("成功");

    }


    /**
     *编辑部门管理列表
     * @param department 编辑的部门
     * @return 状态码
     */
    @RequestMapping("/edit")
    public R departmentedit(@Valid Department department){
        departmentService.departmentedit(department);
        return R.ok("成功");

    }



    /**
     *删除部门管理列表
     * @param deptId 根据deptId删除
     * @return 状态码
     */
    @RequestMapping("/del")
    public R departmentdelete(int deptId){

        departmentService.departmentdelete(deptId);
        return R.ok("成功");
    }
}
